package com.junlaninfo;

/**
 * Created by 辉 on 2020/8/23.
 */
public class Thread01 implements Runnable {
    private int count = 100;

    public void run() {
       while (count > 0) {
            ticket();
        }
    }

    private synchronized void ticket() {
        if (count>0){
            System.out.println(Thread.currentThread().getName() + "正在出售" + (100 - count + 1) + "张票");
            count--;
        }

    }

    public static void main(String[] args) {
        Thread01 thread01 = new Thread01();
        Thread thread1 = new Thread(thread01, "窗口1");
        Thread thread2 = new Thread(thread1, "窗口2");
        thread1.start();
        thread2.start();
    }
}
